package com.jin.lazytool.entity;


import com.jin.lazytool.utils.JinUtils;
import org.luaj.vm2.LuaTable;

import java.awt.*;
import java.awt.event.KeyEvent;

public class KeyReleasedEvent extends KeyDownUpEvent {

    public KeyReleasedEvent(){}
    public KeyReleasedEvent(KeyEvent keyEvent){
        super(keyEvent);
    }

    @Override
    String initDescVal() {
        return "松开按键";
    }

    @Override
    public int execute(Robot robot, int index) throws InterruptedException,NoSuchMethodException {

        if(luaFLag){
            LuaTable lua = JinUtils.evalLua(getLua(), getTime());
            boolean exeFlag = lua.get("exeFlag").toboolean();
            if(exeFlag){
                Thread.sleep(lua.get("time").tolong());
                robot.keyRelease(getKeyCode());
            }
        }else{
            Thread.sleep(getTime());
            robot.keyRelease(getKeyCode());
        }

        return index;
    }

}
